package main

import (
	"context"
	"runtime"
	"sync"

	"gitee.com/pangxianfei/frame/facades"
	_ "gitee.com/pangxianfei/frame/library/config"
	"golang.org/x/sync/errgroup"

	"tmaic/initialize/bootstrap"
)

var groupapp errgroup.Group
var app bootstrap.App

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	ctx, cancel := context.WithCancel(context.Background())
	app.Initialize()
	app.EnablingScheduledTask()
	wg := &sync.WaitGroup{}
	wg.Add(1)

	groupapp.Go(func() error {
		return app.UserHttpServer(ctx, wg).ListenAndServe()
	})

	groupapp.Go(func() error {
		return app.LoginHttpServe(ctx, wg).ListenAndServe()
	})

	if err := groupapp.Wait(); err != nil {
		facades.Log.Info(err.Error())
		cancel()
	}
	wg.Done()
}
